/*
 * Ordenes.java
 *
 * Created on 12 de octubre de 2007, 01:46 AM
 */

package interfaces;

import data.OrdenPlatillo;
import data.Platillo;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.tree.*;
import restaurante.CapturaOrdenes;

/**
 *
 * @author  user
 */
public class Ordenes extends javax.swing.JPanel {
    
    Vector ordenadosV = new Vector();
    Vector ordenadosPV  = new Vector();
    
    /** Creates new form Ordenes */
    public Ordenes() {
        setSize(800,600);
        setPreferredSize(new Dimension(800,600));
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel5 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        menu = new javax.swing.JTree();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ordenados = ordenados = new javax.swing.JList(ordenadosV);
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        comentarios = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        borrar = new javax.swing.JButton();
        aceptar = new javax.swing.JButton();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));

        setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        setPreferredSize(new java.awt.Dimension(317, 351));
        setRequestFocusEnabled(false);
        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.X_AXIS));

        jPanel5.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        jPanel5.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 0, 5));
        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.X_AXIS));

        jPanel3.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        jPanel3.setPreferredSize(new java.awt.Dimension(330, 200));
        jScrollPane3.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        menu.setFont(new java.awt.Font("Tahoma", 0, 10));
        CapturaOrdenes co = new CapturaOrdenes();
        menu.setModel(co.crearMenu());
        menu.setRootVisible(false);
        menu.setToggleClickCount(1);
        menu.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                menuValueChanged(evt);
            }
        });

        jScrollPane3.setViewportView(menu);

        jPanel3.add(jScrollPane3);

        jPanel5.add(jPanel3);

        jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.X_AXIS));

        jPanel4.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        jPanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0));
        ordenados.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 0, 5));
        ordenados.setFont(new java.awt.Font("Tahoma", 0, 10));
        ordenados.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        ordenados.setMaximumSize(new java.awt.Dimension(122, 271));
        ordenados.setPreferredSize(new java.awt.Dimension(80, 270));

        jScrollPane2.setViewportView(ordenados);

        jPanel4.add(jScrollPane2);

        jPanel5.add(jPanel4);

        add(jPanel5);

        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.X_AXIS));

        jPanel2.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 5, 0, 5));
        jPanel2.setPreferredSize(new java.awt.Dimension(315, 10));
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 91));
        comentarios.setColumns(30);
        comentarios.setFont(new java.awt.Font("Monospaced", 0, 12));
        comentarios.setRows(5);
        comentarios.setText("Comentarios");
        comentarios.setPreferredSize(new java.awt.Dimension(315, 20));
        jScrollPane1.setViewportView(comentarios);

        jPanel2.add(jScrollPane1);

        add(jPanel2);

        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.X_AXIS));

        jPanel1.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));
        jPanel1.setPreferredSize(new java.awt.Dimension(317, 35));
        jButton1.setFont(new java.awt.Font("Tahoma", 0, 10));
        jButton1.setText("A\u00f1adir Comentario");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel1.add(jButton1);

        borrar.setFont(new java.awt.Font("Tahoma", 0, 10));
        borrar.setText("Borrar Platillo");
        jPanel1.add(borrar);

        aceptar.setFont(new java.awt.Font("Tahoma", 0, 10));
        aceptar.setText("Aceptar");
        jPanel1.add(aceptar);

        add(jPanel1);

    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        int seleccionado = ordenados.getSelectedIndex();
        OrdenPlatillo op = (OrdenPlatillo)ordenadosPV.get(seleccionado);
        op.setComentario(comentarios.getText());
        ordenadosPV.setElementAt(op, seleccionado);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void menuValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_menuValueChanged
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)menu.getLastSelectedPathComponent();

        if (node == null)
        return;

        Object nodeInfo = node.getUserObject();
        if (node.isLeaf()) {
            Platillo platillo = (Platillo)nodeInfo;
            ordenadosV.addElement(platillo);
            ordenados.setListData(ordenadosV);
            menu.setSelectionPath(null);
            
            OrdenPlatillo op = new OrdenPlatillo();
            op.setEstado("Pendiente");
            ordenadosPV.addElement(op);
        }
    }//GEN-LAST:event_menuValueChanged
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JButton borrar;
    private javax.swing.JTextArea comentarios;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTree menu;
    private javax.swing.JList ordenados;
    // End of variables declaration//GEN-END:variables
}